﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using SmartSpace.UI.Silverlight.Dynamic.DynamicRef;
using SmartSpace.UI.Silverlight.Dynamic.Controls;

namespace SmartSpace.UI.Silverlight.Dynamic.Util
{
    /// <summary>
    /// 视图界面操作公用类
    /// </summary>
    public class ViewLayoutUtil
    {
        private const int LabelWidth = 100;

        /// <summary>
        /// 生成修改视图整体布局
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="viewMetadata"></param>
        /// <param name="container"></param>
        /// <param name="asyncControls"></param>
        /// <param name="fieldControls"></param>
        public static void BuildUI(string userName, ViewMetadata viewMetadata, StackPanel container, List<IAsyncControl> asyncControls, List<PMFDataControl> fieldControls)
        {
            int colCount = 0;

            Grid grid = null;
            foreach (FieldMetadata field in viewMetadata.FieldMetadatas)
            {
                if (field.CanVisit)
                {
                    #region label

                    Label borderLabel = new Label();
                    //读取系统Resources
                    borderLabel.Style = Application.Current.Resources["FH"] as Style;

                    StackPanel labelSp = new StackPanel();
                    labelSp.Orientation = Orientation.Horizontal;
                    labelSp.VerticalAlignment = System.Windows.VerticalAlignment.Center;

                    TextBlock label = new TextBlock();
                    label.Text = field.Caption;
                    label.TextWrapping = TextWrapping.Wrap;

                    if (!field.IsSaveNullable || !field.IsSubmitNullable)
                    {
                        TextBlock labelStar = new TextBlock();
                        labelStar.Text = "*";
                        labelStar.FontSize = 18;
                        labelStar.Foreground = new SolidColorBrush(Colors.Red);

                        labelSp.Children.Add(labelStar);
                    }
                    labelSp.Children.Add(label);

                    borderLabel.Content = labelSp;

                    #endregion

                    #region field

                    //Label borderField = new Label();
                    //borderField.Style = Application.Current.Resources["FC"] as Style;

                    FrameworkElement fieldElement = CreateFieldElement(userName, viewMetadata, field);
                    if (fieldElement is IAsyncControl)
                    {
                        asyncControls.Add((IAsyncControl)fieldElement);
                    }
                    if (fieldElement is PMFDataControl)
                    {
                        fieldControls.Add((PMFDataControl)fieldElement);
                    }

                    //borderField.Content = fieldElement;

                    #endregion

                    //独占一行
                    if (field.IsAbundance)
                    {
                        grid = BuildFormRowGrid(container);
                        grid.Children.Add(fieldElement);
                        grid.Children.Add(borderLabel);

                        Grid.SetColumn(borderLabel, 0);
                        Grid.SetColumn(fieldElement, 1);
                        Grid.SetColumnSpan(fieldElement, 3);

                        colCount = 0;
                        grid = null;
                    }
                    else
                    {
                        if (grid == null)
                        {
                            grid = BuildFormRowGrid(container);
                        }

                        grid.Children.Add(fieldElement);
                        grid.Children.Add(borderLabel);
                        Grid.SetColumn(borderLabel, colCount++);
                        Grid.SetColumn(fieldElement, colCount++);

                        if (colCount > 3)
                        {
                            grid = null;
                            colCount = 0;
                        }
                    }
                }
            }
        }

        /// <summary>
        /// 生成只读视图整体布局
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="viewMetadata"></param>
        /// <param name="container"></param>
        public static void BuildReadUI(string userName, ViewMetadata viewMetadata, StackPanel container)
        {
            int colCount = 0;

            Grid grid = null;
            foreach (FieldMetadata field in viewMetadata.FieldMetadatas)
            {
                if (field.CanVisit)
                {
                    #region label

                    Label borderLabel = new Label();
                    borderLabel.Style = Application.Current.Resources["FH"] as Style;

                    TextBlock label = new TextBlock();
                    label.Text = field.Caption;
                    label.TextWrapping = TextWrapping.Wrap;
                    label.VerticalAlignment = System.Windows.VerticalAlignment.Center;

                    borderLabel.Content = label;

                    #endregion

                    #region field

                    Label borderField = new Label();
                    borderField.Style = Application.Current.Resources["FC"] as Style;

                    FrameworkElement fieldElement = CreateFieldElement(userName, viewMetadata, field, true);

                    borderField.Content = fieldElement;

                    #endregion

                    if (field.IsAbundance)
                    {
                        grid = BuildFormRowGrid(container);
                        grid.Children.Add(borderField);
                        grid.Children.Add(borderLabel);

                        Grid.SetColumn(borderLabel, 0);
                        Grid.SetColumn(borderField, 1);
                        Grid.SetColumnSpan(borderField, 3);

                        colCount = 0;
                        grid = null;
                    }
                    else
                    {
                        if (grid == null)
                        {
                            grid = BuildFormRowGrid(container);
                        }

                        grid.Children.Add(borderField);
                        grid.Children.Add(borderLabel);
                        Grid.SetColumn(borderLabel, colCount++);
                        Grid.SetColumn(borderField, colCount++);

                        if (colCount > 3)
                        {
                            grid = null;
                            colCount = 0;
                        }
                    }
                }
            }
        }

        public static Grid BuildFormRowGrid(StackPanel container)
        {
            ColumnDefinition columnLabel1;
            ColumnDefinition columnField1;
            ColumnDefinition columnLabel2;
            ColumnDefinition columnField2;

            Grid grid = new Grid();
            columnLabel1 = new ColumnDefinition();
            columnLabel1.Width = new GridLength(LabelWidth);
            grid.ColumnDefinitions.Add(columnLabel1);
            columnField1 = new ColumnDefinition();
            columnField1.Width = new GridLength(1, GridUnitType.Star);
            grid.ColumnDefinitions.Add(columnField1);
            columnLabel2 = new ColumnDefinition();
            columnLabel2.Width = new GridLength(LabelWidth);
            grid.ColumnDefinitions.Add(columnLabel2);
            columnField2 = new ColumnDefinition();
            columnField2.Width = new GridLength(1, GridUnitType.Star);
            grid.ColumnDefinitions.Add(columnField2);
            container.Children.Add(grid);

            return grid;
        }

        /// <summary>
        /// 通过FiledMetadata类型生成具体控件
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="viewMetadata"></param>
        /// <param name="metadata"></param>
        /// <param name="isReadonly"></param>
        /// <returns></returns>
        public static FrameworkElement CreateFieldElement(string userName, ViewMetadata viewMetadata, FieldMetadata metadata, bool? isReadonly = null)
        {
            bool readOnly = !metadata.CanModify;
            if (isReadonly != null)
            {
                readOnly = isReadonly.Value;
            }

            FrameworkElement element = null;

            if (metadata.Type == "date")
            {
                element = new DateTimeControl();
                System.Windows.Data.Binding binding = new System.Windows.Data.Binding();
                binding.Path = new PropertyPath("[" + metadata.Name + "]");
                binding.Mode = System.Windows.Data.BindingMode.TwoWay;

                (element as PMFDataControl).SetBinding(PMFDataControl.DataSourceProperty, binding);
                (element as PMFDataControl).IsReadOnly = readOnly;
            }
            else if (metadata.Type == "dictionary")
            {
                element = new SingleDictionaryControl(metadata.TypeFlag);

                System.Windows.Data.Binding binding = new System.Windows.Data.Binding();
                binding.Path = new PropertyPath("[" + metadata.Name + "]");
                binding.Mode = System.Windows.Data.BindingMode.TwoWay;

                //增加配置 当数据为空或者异常时通知控件显示
                binding.UpdateSourceTrigger = System.Windows.Data.UpdateSourceTrigger.Explicit;
                binding.ValidatesOnExceptions = true;
                binding.ValidatesOnDataErrors = true;
                binding.ValidatesOnNotifyDataErrors = true;
                binding.NotifyOnValidationError = true;

                (element as PMFDataControl).SetBinding(PMFDataControl.DataSourceProperty, binding);
                (element as PMFDataControl).IsReadOnly = readOnly;
            }
            else if (metadata.Type == "org")
            {
                element = new OrgListControl(false, userName);

                System.Windows.Data.Binding binding = new System.Windows.Data.Binding();
                binding.Path = new PropertyPath("[" + metadata.Name + "]");
                binding.Mode = System.Windows.Data.BindingMode.TwoWay;

                binding.UpdateSourceTrigger = System.Windows.Data.UpdateSourceTrigger.Explicit;
                binding.ValidatesOnExceptions = true;
                binding.ValidatesOnDataErrors = true;
                binding.ValidatesOnNotifyDataErrors = true;
                binding.NotifyOnValidationError = true;

                (element as PMFDataControl).SetBinding(PMFDataControl.DataSourceProperty, binding);
                (element as PMFDataControl).IsReadOnly = readOnly;
            }
            else if (metadata.Type == "orglist")
            {
                element = new OrgListControl(false, userName);

                System.Windows.Data.Binding binding = new System.Windows.Data.Binding();
                binding.Path = new PropertyPath("[" + metadata.Name + "]");
                binding.Mode = System.Windows.Data.BindingMode.TwoWay;

                binding.UpdateSourceTrigger = System.Windows.Data.UpdateSourceTrigger.Explicit;
                binding.ValidatesOnExceptions = true;
                binding.ValidatesOnDataErrors = true;
                binding.ValidatesOnNotifyDataErrors = true;
                binding.NotifyOnValidationError = true;

                (element as PMFDataControl).SetBinding(PMFDataControl.DataSourceProperty, binding);
                (element as PMFDataControl).IsReadOnly = readOnly;
            }
            else if (metadata.Type == "suborg")
            {
                element = new OrgListControl(true, userName);

                System.Windows.Data.Binding binding = new System.Windows.Data.Binding();
                binding.Path = new PropertyPath("[" + metadata.Name + "]");
                binding.Mode = System.Windows.Data.BindingMode.TwoWay;

                binding.UpdateSourceTrigger = System.Windows.Data.UpdateSourceTrigger.Explicit;
                binding.ValidatesOnExceptions = true;
                binding.ValidatesOnDataErrors = true;
                binding.ValidatesOnNotifyDataErrors = true;
                binding.NotifyOnValidationError = true;

                (element as PMFDataControl).SetBinding(PMFDataControl.DataSourceProperty, binding);
                (element as PMFDataControl).IsReadOnly = readOnly;
            }
            else if (metadata.Type == "subuser")
            {
                element = new UserListControl(userName);

                System.Windows.Data.Binding binding = new System.Windows.Data.Binding();
                binding.Path = new PropertyPath("[" + metadata.Name + "]");
                binding.Mode = System.Windows.Data.BindingMode.TwoWay;

                binding.UpdateSourceTrigger = System.Windows.Data.UpdateSourceTrigger.Explicit;
                binding.ValidatesOnExceptions = true;
                binding.ValidatesOnDataErrors = true;
                binding.ValidatesOnNotifyDataErrors = true;
                binding.NotifyOnValidationError = true;

                (element as UserListControl).SetBinding(UserListControl.SelectedUserProperty, binding);
                (element as UserListControl).IsReadOnly = readOnly;
            }
            //else if (metadata.Type.StartsWith("suborguser"))
            //{
            //    int typeCode = 0;
            //    string[] items = metadata.Type.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
            //    if (items.Length == 2)
            //    {
            //        typeCode = Convert.ToInt32(items[1]);
            //    }
            //    element = new SubOrgUserListControl(userName, typeCode);

            //    System.Windows.Data.Binding binding = new System.Windows.Data.Binding();
            //    binding.Path = new PropertyPath("[" + metadata.Name + "]");
            //    binding.Mode = System.Windows.Data.BindingMode.TwoWay;

            //    binding.UpdateSourceTrigger = System.Windows.Data.UpdateSourceTrigger.Explicit;
            //    binding.ValidatesOnExceptions = true;
            //    binding.ValidatesOnDataErrors = true;
            //    binding.ValidatesOnNotifyDataErrors = true;
            //    binding.NotifyOnValidationError = true;

            //    (element as SubOrgUserListControl).SetBinding(SubOrgUserListControl.SelectedUserProperty, binding);
            //    (element as SubOrgUserListControl).IsReadOnly = readOnly;
            //}
            else if (metadata.Type == "attachment")
            {
                element = new AttachmentControl();

                System.Windows.Data.Binding binding = new System.Windows.Data.Binding();
                binding.Path = new PropertyPath("[" + metadata.Name + "]");
                binding.Mode = System.Windows.Data.BindingMode.TwoWay;

                binding.UpdateSourceTrigger = System.Windows.Data.UpdateSourceTrigger.Explicit;
                binding.ValidatesOnExceptions = true;
                binding.ValidatesOnDataErrors = true;
                binding.ValidatesOnNotifyDataErrors = true;
                binding.NotifyOnValidationError = true;


                (element as PMFDataControl).SetBinding(PMFDataControl.DataSourceProperty, binding);
                (element as PMFDataControl).IsReadOnly = readOnly;
            }
            else if (metadata.Type == "code")
            {
                element = new CodeControl(viewMetadata.Caption, userName);
                System.Windows.Data.Binding binding = new System.Windows.Data.Binding();
                binding.Path = new PropertyPath("[" + metadata.Name + "]");
                binding.Mode = System.Windows.Data.BindingMode.TwoWay;

                (element as CodeControl).SetBinding(CodeControl.CodeProperty, binding);
                (element as CodeControl).IsReadOnly = readOnly;
            }
            //else if (metadata.Type == "word")
            //{
            //    element = new WordControl(viewMetadata.TableId, viewMetadata.TableName, userName, viewMetadata.ViewId);
            //    System.Windows.Data.Binding binding = new System.Windows.Data.Binding();
            //    binding.Path = new PropertyPath("[" + metadata.Name + "]");
            //    binding.Mode = System.Windows.Data.BindingMode.TwoWay;
            //    binding.UpdateSourceTrigger = System.Windows.Data.UpdateSourceTrigger.Explicit;
            //    binding.ValidatesOnExceptions = true;
            //    binding.ValidatesOnDataErrors = true;
            //    binding.ValidatesOnNotifyDataErrors = true;
            //    binding.NotifyOnValidationError = true;

            //    (element as WordControl).SetBinding(WordControl.WordSourceProperty, binding);
            //    (element as WordControl).IsReadOnly = readOnly;
            //}
            else if (metadata.Type == "textarea")
            {
                //element = new TextBox();
                //(element as TextBox).Height = 150;
                //(element as TextBox).TextWrapping = TextWrapping.Wrap;
                //(element as TextBox).AcceptsReturn = true;
                //System.Windows.Data.Binding binding = new System.Windows.Data.Binding();
                //binding.Path = new PropertyPath("[" + metadata.Name + "]");
                //binding.Mode = System.Windows.Data.BindingMode.TwoWay;
                
                //(element as TextBox).SetBinding(TextBox.TextProperty, binding);
                //(element as TextBox).IsReadOnly = readOnly;
                //(element as TextBox).TextChanged += new TextChangedEventHandler(ViewLayoutUtil_TextChanged);
                ////为大文本控件，添加右键菜单
                //new MenuTextControl().creatMenu(element as TextBox);

                element = new TextControl();
                (element as TextControl).Height = 150;
                (element as TextControl).TextWrapping = TextWrapping.Wrap;
                (element as TextControl).AcceptsReturn = true;
                System.Windows.Data.Binding binding = new System.Windows.Data.Binding();
                binding.Path = new PropertyPath("[" + metadata.Name + "]");
                binding.Mode = System.Windows.Data.BindingMode.TwoWay;
                binding.UpdateSourceTrigger = System.Windows.Data.UpdateSourceTrigger.Explicit;
                binding.ValidatesOnExceptions = true;
                binding.ValidatesOnDataErrors = true;
                binding.ValidatesOnNotifyDataErrors = true;
                binding.NotifyOnValidationError = true;

                (element as PMFDataControl).SetBinding(PMFDataControl.DataSourceProperty, binding);
                (element as PMFDataControl).IsReadOnly = readOnly;
            }
            //else if (metadata.Type.StartsWith("dp:"))
            //{
            //    //dp:{[8]:_entity_bmdbd:41:ID};{_entity_csdbd:44:BMDBDID};{_entity_cbrdbd:47:BMDBDID}
            //    /*
            //    string[] items = metadata.Type.Replace("dp:", string.Empty).Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                
            //    string dpTableName = items[0];
            //    int dpViewId = Convert.ToInt32(items[1]);
            //    string fieldName = items[2];
            //    */
            //    //element = new DependenceControl(dpTableName, dpViewId, userName,fieldName);
            //    element = new DependenceControl(userName, viewMetadata.TableName);
            //    System.Windows.Data.Binding binding = new System.Windows.Data.Binding();
            //    binding.Path = new PropertyPath("[" + metadata.Name + "]");
            //    binding.Mode = System.Windows.Data.BindingMode.TwoWay;

            //    (element as DependenceControl).SetBinding(DependenceControl.SelectedDataProperty, binding);
            //    (element as DependenceControl).IsReadOnly = readOnly;
            //}
            else if (metadata.Type == "editor")
            {
                element = new EditorControl();
                System.Windows.Data.Binding binding = new System.Windows.Data.Binding();
                binding.Path = new PropertyPath("[" + metadata.Name + "]");
                binding.Mode = System.Windows.Data.BindingMode.TwoWay;

                binding.UpdateSourceTrigger = System.Windows.Data.UpdateSourceTrigger.Explicit;
                binding.ValidatesOnExceptions = true;
                binding.ValidatesOnDataErrors = true;
                binding.ValidatesOnNotifyDataErrors = true;
                binding.NotifyOnValidationError = true;

                (element as EditorControl).SetBinding(EditorControl.TextProperty, binding);
                (element as EditorControl).IsReadOnly = readOnly;
            }
            else
            {
                element = new TextControl();
                System.Windows.Data.Binding binding = new System.Windows.Data.Binding();
                binding.Path = new PropertyPath("[" + metadata.Name + "]");
                binding.Mode = System.Windows.Data.BindingMode.TwoWay;
                binding.UpdateSourceTrigger = System.Windows.Data.UpdateSourceTrigger.Explicit;
                binding.ValidatesOnExceptions = true;
                binding.ValidatesOnDataErrors = true;
                binding.ValidatesOnNotifyDataErrors = true;
                binding.NotifyOnValidationError = true;

                (element as PMFDataControl).SetBinding(PMFDataControl.DataSourceProperty, binding);
                (element as PMFDataControl).IsReadOnly = readOnly;
            }

            try
            {
                (element as PMFDataControl).IsSaveNullable = metadata.IsSaveNullable;
                (element as PMFDataControl).IsSubmitNullable = metadata.IsSubmitNullable;
                (element as PMFDataControl).IsReadOnly = readOnly;
            }
            catch
            {
            }

            element.Margin = new Thickness(1);
            return element;
        }

        //#region Parts

        ///// <summary>
        ///// 生成领导审核意见详情部件
        ///// CommentsPart
        ///// </summary>
        ///// <param name="userName"></param>
        ///// <param name="viewMetadata"></param>
        ///// <param name="data"></param>
        ///// <param name="container"></param>
        //public static void BuildParts(string userName, ViewMetadata viewMetadata, DetailData data, StackPanel container)
        //{
        //    FrameworkElement element = new CommentsPart(userName,viewMetadata.TableName, data.Id);
        //    element.Margin = new Thickness(5);
        //    container.Children.Add(element);
        //}

        //#endregion

        //#region Relation

        ///// <summary>
        /////将当前表数据关联的数据生成TabItem
        /////多个关联生成多个TabItem
        ///// </summary>
        ///// <param name="userName"></param>
        ///// <param name="viewMetadata"></param>
        ///// <param name="data"></param>
        ///// <param name="container"></param>
        //public static void BuildRelations(string userName, ViewMetadata viewMetadata, DetailData data, TabControl container, out List<IValidationPart> parts)
        //{
        //    parts = new List<IValidationPart>();

        //    foreach (RelationMetadata relation in viewMetadata.RelationMetadatas)
        //    {
        //        if (relation.IsCanView)
        //        {
        //            TabItem item = new TabItem();
        //            item.Header = relation.TableCaption;

        //            FrameworkElement element = new RelationListTemplateView(
        //                userName,
        //                relation.TableName,
        //                relation.ViewId,
        //                viewMetadata.TableId,
        //                viewMetadata.TableName,
        //                viewMetadata.ViewId,
        //                data.Id);

        //            if (element is IValidationPart && relation.SubmitValidation)
        //            {
        //                parts.Add(element as IValidationPart);
        //            }

        //            (element as RelationListTemplateView).Initiate(
        //                relation.IsCanAdd,
        //                relation.IsCanDelete,
        //                relation.IsCanEdit,
        //                relation.CanImport,
        //                relation.SubmitValidation);
        //            (element as RelationListTemplateView).Initiate(relation);

        //            item.Content = element;
        //            container.Items.Add(item);
        //        }
        //    }
        //}

        //public static FrameworkElement BuildRelation(string userName, ViewMetadata viewMetadata, DetailData data, RelationMetadata relation, TabControl container)
        //{
        //    if (relation.IsCanView)
        //    {
        //        TabItem item = new TabItem();
        //        item.Header = relation.TableCaption;

        //        FrameworkElement element = new RelationListTemplateView(
        //            userName,
        //            relation.TableName,
        //            relation.ViewId,
        //            viewMetadata.TableId,
        //            viewMetadata.TableName,
        //            viewMetadata.ViewId,
        //            data.Id);
        //        (element as RelationListTemplateView).Initiate(relation.IsCanAdd, relation.IsCanDelete, relation.IsCanEdit, relation.CanImport, relation.SubmitValidation);
        //        (element as RelationListTemplateView).Initiate(relation);

        //        item.Content = element;
        //        container.Items.Add(item);
        //        return element;
        //    }
        //    return null;
        //}

        ///// <summary>
        ///// 构建只读的列表页面
        ///// </summary>
        ///// <param name="userName"></param>
        ///// <param name="viewMetadata"></param>
        ///// <param name="data"></param>
        ///// <param name="relation"></param>
        ///// <param name="container"></param>
        ///// <returns></returns>
        //public static FrameworkElement BuildRelationReadOnly(string userName, ViewMetadata viewMetadata, DetailData data, RelationMetadata relation, TabControl container)
        //{
        //    if (relation.IsCanView)
        //    {
        //        TabItem item = new TabItem();
        //        item.Header = relation.TableCaption;

        //        FrameworkElement element = new RelationListTemplateView(
        //            userName,
        //            relation.TableName,
        //            relation.ViewId,
        //            viewMetadata.TableId,
        //            viewMetadata.TableName,
        //            viewMetadata.ViewId,
        //            data.Id);
        //        (element as RelationListTemplateView).Initiate(false, false, false, false, relation.SubmitValidation);
        //        item.Content = element;
        //        container.Items.Add(item);
        //        return element;
        //    }
        //    return null;
        //}

        ///// <summary>
        ///// 生成关联数据的界面
        ///// </summary>
        ///// <param name="userName"></param>
        ///// <param name="viewMetadata"></param>
        ///// <param name="data"></param>
        ///// <param name="relation"></param>
        ///// <param name="container"></param>
        ///// <returns></returns>
        //public static FrameworkElement BuildDependence(
        //    string userName, 
        //    ViewMetadata viewMetadata, 
        //    DetailData data, 
        //    DependenceMetadata dependence)
        //{
        //    RelationDetailTemplateView element = new RelationDetailTemplateView();
        //    element.Initiate(
        //        userName,
        //        dependence.OnTableName,
        //        dependence.OnViewId,
        //        data.DependenceId,
        //        string.Empty,
        //        0,
        //        0,
        //        true);
        //    return element;
        //}

        ///// <summary>
        ///// 在表数据展示页面生成内联(Inline)数据
        ///// 内联数据可为列表或者TabControl
        ///// </summary>
        ///// <param name="userName"></param>
        ///// <param name="viewMetadata"></param>
        ///// <param name="data"></param>
        ///// <param name="relation"></param>
        ///// <param name="container"></param>
        ///// <returns></returns>
        //public static RelationInlineListTemplateView BuildRelationInline(string userName, ViewMetadata viewMetadata, DetailData data, RelationMetadata relation, StackPanel container)
        //{
        //    if (relation.IsCanView)
        //    {
        //        RelationInlineListTemplateView element = new RelationInlineListTemplateView(
        //            userName,
        //            relation.TableName,
        //            relation.ViewId,
        //            viewMetadata.TableId,
        //            viewMetadata.TableName,
        //            viewMetadata.ViewId,
        //            data.Id);
        //        element.Initiate(relation.IsCanAdd, relation.IsCanDelete, relation.IsCanEdit, relation.CanImport, relation.TableCaption, relation.CaptionField, relation.CaptionFormat);
        //        container.Children.Add(element);

        //        return element;
        //    }
        //    return null;
        //}

        //#endregion
    }
}
